<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /* 
      ES3:构造函数+原型
      
    
    */

      /* function Person(name, age) {
        this.name = name;
        this.age = age;
      }

      Person.prototype.eat = function () {
        console.log("eat");
      };

      Person.hello = "world"

      const p1 = new Person("xiaowang", 18); */

      /* 
        ES6: class类定义
      
      
      */

      //定义一个类
      class Person {
        //构造器函数:当这个类被实例化的时候,会立马调用构造器函数,并接受实例化时传递的参数
        //构造器函数内部的this指向实例化对象
        constructor(name, age) {
          //公有属性
          this.name = name;
          this.age = age;
          // this.sex = "男";
        }

        //设置给实例化对象的一个属性
        sex = "男";

        //公有方法
        eat() {
          console.log("eat");
        }

        //Person类的静态属性
        static hello = "world";
      }

      console.log(typeof Person);
      const p1 = new Person("小明", 20);
      console.log(p1);
      console.log(Person.hello);
    </script>
  </body>
</html>
